package cn.stylefeng.guns.modular.myorder.controller;

import cn.stylefeng.guns.modular.myorder.pojo.request.MyorderRequest;
import cn.stylefeng.guns.modular.myorder.service.MyorderService;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 订单管理控制器
 *
 * @author zhu
 * @date 2021/09/25 18:20
 */
@RestController
@ApiResource(name = "订单管理")
public class MyorderController {

    @Resource
    private MyorderService myorderService;

    /**
     * 添加
     *
     * @author zhu
     * @date 2021/09/25 18:20
     */
    @PostResource(name = "添加", path = "/myorder/add")
    public ResponseData add(@RequestBody @Validated(MyorderRequest.add.class) MyorderRequest myorderRequest) {
        myorderService.add(myorderRequest);
        return new SuccessResponseData();
    }

    /**
     * 删除
     *
     * @author zhu
     * @date 2021/09/25 18:20
     */
    @PostResource(name = "删除", path = "/myorder/delete")
    public ResponseData delete(@RequestBody @Validated(MyorderRequest.delete.class) MyorderRequest myorderRequest) {
        myorderService.del(myorderRequest);
        return new SuccessResponseData();
    }

    /**
     * 编辑
     *
     * @author zhu
     * @date 2021/09/25 18:20
     */
    @PostResource(name = "编辑", path = "/myorder/edit")
    public ResponseData edit(@RequestBody @Validated(MyorderRequest.edit.class) MyorderRequest myorderRequest) {
        myorderService.edit(myorderRequest);
        return new SuccessResponseData();
    }

    /**
     * 查看详情
     *
     * @author zhu
     * @date 2021/09/25 18:20
     */
    @GetResource(name = "查看详情", path = "/myorder/detail")
    public ResponseData detail(@Validated(MyorderRequest.detail.class) MyorderRequest myorderRequest) {
        return new SuccessResponseData(myorderService.detail(myorderRequest));
    }

    /**
     * 获取列表
     *
     * @author zhu
     * @date 2021/09/25 18:20
     */
    @GetResource(name = "获取列表", path = "/myorder/list")
    public ResponseData list(MyorderRequest myorderRequest) {
        return new SuccessResponseData(myorderService.findList(myorderRequest));
    }

    /**
     * 获取列表（带分页）
     *
     * @author zhu
     * @date 2021/09/25 18:20
     */
    @GetResource(name = "分页查询", path = "/myorder/page")
    public ResponseData page(MyorderRequest myorderRequest) {
        return new SuccessResponseData(myorderService.findPage(myorderRequest));
    }

}